package com.example.administrator.shuju;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/22.
 */
public class MyAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private ArrayList<LianXiRen>lianXiRenArrayList;

    MyAdapter(Context context, ArrayList<LianXiRen>list){
        this.lianXiRenArrayList = list;
        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return this.lianXiRenArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LianXiRen lianXiRen = this.lianXiRenArrayList.get(i);
        if (view == null) {
            view = layoutInflater.inflate(R.layout.listview,null);

            ImageView imageView = (ImageView)view.findViewById(R.id.image);
            TextView textView = (TextView)view.findViewById(R.id.text);
            TextView textView1 = (TextView)view.findViewById(R.id.text2);

            imageView.setImageResource(R.drawable.n);
            textView.setText(lianXiRen.getName());
            textView1.setText(lianXiRen.getNumber());

            MyTag myTag = new MyTag();
            myTag.imageView = imageView;
            myTag.textView = textView;
            myTag.textView1 = textView1;

            view.setTag(myTag);
            return view;

        }else {
            MyTag myTag = (MyTag)view.getTag();
            ImageView imageView = myTag.imageView;
            TextView textView = myTag.textView;
            TextView textView1 = myTag.textView1;

            imageView.setImageResource(R.drawable.n);
            textView.setText(lianXiRen.getName());
            textView1.setText(lianXiRen.getNumber());

            return view;


        }
    }
    class MyTag {
        ImageView imageView;
        TextView textView;
        TextView textView1;
    }
}
